Skip to content

ImGui 1.92.+ support#251

Closed
mctb32 wants to merge 12 commits intoDiligentGraphics:imgui_updatefrom
mctb32:master
Closed

ImGui 1.92.+ support#251
mctb32 wants to merge 12 commits intoDiligentGraphics:imgui_updatefrom
mctb32:master

Conversation

@mctb32
Copy link
Copy Markdown
Contributor

@mctb32 mctb32 commented Jul 12, 2025

In regards to this issue: #249

  • switched ImGui submodule to official repository version 1.92.1
  • updated ImGuiDiligentRender to support the new texture API with scaling fonts
  • added public IMGUI_DEFINE_MATH_OPERATORS define to Diligent-Imgui target in CMakeLists.txt (not sure about this one, if someone wants to provide custom math operators, but the alternative was to add this define to every sample/tutorial project in diligent).

I tested everything on Windows in all backends and it works nice. Other platforms should work as well as the changes were relatively straightforward, but some testing would of course be needed.

I noticed that some Diligent samples use invalid ImGui flags for some controls and this is now being caught by assertions inside ImGui in debug builds. (for example ImGui::InputFloat() does not support ImGuiInputTextFlags_EnterReturnsTrue flag). These should be fixed, but they are in another repo.

@mctb32 mctb32 requested a review from TheMostDiligent as a code owner July 12, 2025 11:11
@TheMostDiligent
Copy link
Copy Markdown
Contributor

TheMostDiligent commented Jul 12, 2025

The main problem was with the MacOS - did you have a chance to test it?

@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 12, 2025

The main problem was with the MacOS - did you have a chance to test it?

Not yet. I'm new to Mac development but I'll try to test it.

@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 13, 2025

Ok, I got it working on MacOS. Tested in XCode with OpenGL and Vulkan (via MoltenVK) backends and everything looks good.

The problem was that the function ImGui_ImplOSX_HandleEvent(NSEvent*, NSView*) has been made private in newer imgui versions. From what I've seen in the source, the backend registers a custom input monitor and is supposed to handle events on its own. But this didn't work for me. Something in Diligent native/sample app osx code is consuming the events, or preventing them from reaching the internal imgui monitor. I tried to figure it out, forward the events to imgui somehow, but I gave up and I simply copied the internal function over so everything works like before.

I hope this is acceptable. After all this backend should not be used in production - there's a comment at the top of the file "Not well tested. If you want a portable application, prefer using the GLFW or SDL platform Backends on Mac.". But for running Diligent samples it should be fine.

I also got rid of the extra imgui_v1.85 target/thirdparty folder that for some reason was used to host the old osx imgui backend files.

@TheMostDiligent
Copy link
Copy Markdown
Contributor

@mctb32 Thanks for submitting this change and sorry for delay.

This unfortunately does not fully work on MacOS. While rendering is OK, the app crashes when handling the input. For example, clicking on input field reproduces the issue:

Screen.Recording.2025-07-24.at.7.57.21.PM.mov

The problem is that Diligent examples use separate threads for rendering and input handling, while ImGui only supports single-threaded.
This is the reason why there are these 1.85 implementation files - this is the last version where it worked OK.
ocornut/imgui#5940

@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 25, 2025

@TheMostDiligent Yes, I can see this happening for me too. Thanks for the info and sorry I missed that.
I'll take a look at it over the weekend and see if I can figure something out.

@TheMostDiligent
Copy link
Copy Markdown
Contributor

Thank you!
There is a PR that is supposed to fix this: ocornut/imgui#6528, but for some reason it is not merged.

// ----------------------------------------------------------------
// 1) CREATE
// ----------------------------------------------------------------
if (tex->Status == ImTextureStatus_WantCreate)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if - else if - else if will look a bit cleaner than blocks if multiple returns

Comment thread Imgui/src/ImGuiDiligentRenderer.cpp Outdated

ITexture* pTexture = nullptr;
m_pDevice->CreateTexture(desc, &init, &pTexture);
pTexture->AddRef();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be redundant. CreateTexture already returns a texture with one reference, this adds another one. So after DestroyTexture releases one reference, another still remains.

ITexture* pTexture = nullptr;
m_pDevice->CreateTexture(desc, &init, &pTexture);
pTexture->AddRef();
ITextureView* ptexView = pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to AddRef the texture view. The texture is kept in the BackendUserData, so all its views will be kept alive until it is released.

Comment thread Imgui/src/ImGuiDiligentRenderer.cpp Outdated
{
Box dstBox{Uint32(tex->UpdateRect.x), Uint32(tex->UpdateRect.x + tex->UpdateRect.w),
Uint32(tex->UpdateRect.y), Uint32(tex->UpdateRect.y + tex->UpdateRect.h),
0, 1}; // Z range
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Z range may be omitted - it is set to 0..1 by default.

Comment thread Imgui/src/ImGuiDiligentRenderer.cpp Outdated
Comment on lines +914 to +917
if (ITextureView* pTextureView = reinterpret_cast<ITextureView*>(tex->GetTexID()))
{
pTextureView->Release();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to keep the texture view reference.

Comment on lines +934 to +937
if (pDrawData->Textures != nullptr)
for (ImTextureData* tex : *pDrawData->Textures)
if (tex->Status != ImTextureStatus_OK)
UpdateTexture(pCtx, tex);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add braces for ratability.

@TheMostDiligent TheMostDiligent changed the base branch from master to imgui_update July 25, 2025 14:56
@TheMostDiligent
Copy link
Copy Markdown
Contributor

I created a branch for imgui update.
Let's first merge the renderer changes, since they look good, and then work on MacOS issues to separate the problems.

code readability
@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 25, 2025

I created a branch for imgui update. Let's first merge the renderer changes, since they look good, and then work on MacOS issues to separate the problems.

Great! Implemented the changes you requested.

@TheMostDiligent
Copy link
Copy Markdown
Contributor

Can you remove all macos changes from this PR - we will handle MacOS separately

mctb32 added 2 commits July 25, 2025 21:49
This reverts commit 244e7bc.
This reverts commit 3ba093c.
@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 25, 2025

Yes - no problem, but if I do that, the MacOS build will be failing. Is that ok?
It's failing in the old 1.85 macos backend that uses apis no longer available in the new imgui.

@TheMostDiligent
Copy link
Copy Markdown
Contributor

We can make some temporary fixes to make the files compile. We will fix them later. This is a work branch

@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Jul 26, 2025

@TheMostDiligent Ok. I reverted the macos related changes. But then I also updated the legacy 1.85 backend to use the new imgui IO api so it now compiles with 1.92.1+. I used some AI help + some bits from the new backends, but I also did some more extensive testing this time so I hope it works as expected.

@TheMostDiligent TheMostDiligent force-pushed the imgui_update branch 3 times, most recently from f145b8f to 7013506 Compare August 4, 2025 01:03
@TheMostDiligent
Copy link
Copy Markdown
Contributor

Completed update to 1.92.1 in 5786b70.
@mctb32 thank you for your help.

@mctb32
Copy link
Copy Markdown
Contributor Author

mctb32 commented Aug 4, 2025

Completed update to 1.92.1 in 5786b70. @mctb32 thank you for your help.

No problem. If this setup works out, than going forward I think you should be able to update imgui regularly, as I don't think they are planning any more breaking backend changes any time soon.

@TheMostDiligent
Copy link
Copy Markdown
Contributor

Yes. There were quite a lot of changes needed this time, hopefully it will be smoother from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants